<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery"></t:base>
<!DOCTYPE html>
<html>
 <head>
  <title>物流仓库信息表</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
	 <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
	 <script type="text/javascript" src="plug-in/Validform/js/Validform_v5.3.1_min_zh-cn.js"></script>
  <script type="text/javascript">

	$(document).ready(function () {
		$.ajax({
            type:"GET",
            url:"cbsWarehouseController.do?getProvince",
            dataType:"json",
            success:function (data) {
                var tbs = data.obj;
                var  html = "<option value='0'>--请选择--</option>";
                for (i in tbs){
                    html += '<option  value='+tbs[i].territoryCode+'>'+tbs[i].territoryName+'</option>';
                }
                $("#sheng").html(html);

            }
		})

    })
    // var form=$("#formobj").Validform({
    //     ignoreHidden:true,
    //     postonce:true,
    //     showAllError : true,
    //     ajaxPost:true,
    //     tiptype:3,
    // })
	  function getCity() {
		  var province = $("#sheng").val();
          $.ajax({
              type:"GET",
			  data:{"code":province},
              url:"cbsWarehouseController.do?getCity",
              dataType:"json",
              success:function (data) {
                  var tbs = data.obj;
                  var  html = "";
                  for (i in tbs){
                      html += '<option  value='+tbs[i].id+'>'+tbs[i].territoryName+'</option>';
                  }
                  $("#city").html(html);

              }
          })
      }
      $(function () {
          $("#btn").css("pointer-events","auto");
      })
      function addWare() {
          $("#btn").css("pointer-events","none");
          var t1 = $("#t1").html();
          var t2 = $("#t2").html();
          var t3 = $("#t3").html();
          var t4 = $("#t4").html();
          var cityId = $("#cityId").val();
          var cityId2 = $("#cityId2").val();
         var cityId3  = $("#cityId3").val();
          var cityId4  = $("#cityId4").val();
			var name = $("#name").val();

			if(name==""){
			    $("#isName").show();
			    tip("请填写仓库名称");
                $("#btn").css("pointer-events","auto");
			    return ;
			}
          var code = $("#code").val();
			if (code==""){
			    $("#isCode").show();
			    tip("请填写仓库代码");
                $("#btn").css("pointer-events","auto");
			    return ;
			}
          var phone = $("#phone").val();
			if (phone==""){
                $("#isPhoe").show();
                $("#btn").css("pointer-events","auto");
                return;
			}
          var email = $("#email").val();
			if(email==""){
			    $("#isEmail").show();
                $("#btn").css("pointer-events","auto");
                return;
			}
          var userName = $("#userName").val();
			if (userName==""){
			    $("#isUserName").show();
                $("#btn").css("pointer-events","auto");
			    return;
			}
          var address = $("#address").val();
			if(address==""){
			    $("#isAddress").show();
                $("#btn").css("pointer-events","auto");
			    return;
			}
          if (name==code){
              tip("同一物流仓库名称和代码不能重复");
              $("#btn").css("pointer-events","auto");
              return false;
          }
          var logistics = $("#logistics").val();
          var province = $("#sheng").val();
          var city = $("#city").val();
          if (city=="0"){
              tip("仓库所在地请选择到城市");
              $("#btn").css("pointer-events","auto");
              return false;
		  }
          // //调用formValidata 进行验证，并能阻止提交
          // if(!form.check(true)){
          //     form.submitForm(false);
          //     return;
          // }

		  $.ajax({
			  type:"POST",
			  data:{"name":name},
			  url:"cbsWarehouseController.do?ifExist",
			  dataType:"json",
			  success:function (data) {

					if(data.success){
                        $.ajax({
                            type:"POST",
                            data:{"name":name,"code":code,"logistics":logistics,"province":province,"city":city
                                ,"cityId":cityId,"cityId2":cityId2,"cityId3":cityId3,"cityId4":cityId4,
                                "t1":t1,"t2":t2,"t3":t3,"t4":t4,"phone":phone,"email":email,"userName":userName,
                                "address":address
                            },
                            url:"cbsWarehouseController.do?doAdd",
                            dataType:"json",
                            success:function (data) {
                                jQuery.messager.confirm('提示:','确定要添加吗?',function(event){

                                    if(event){
                                        tip("添加成功");
                                        setTimeout("  addOneTab(\"物流仓库管理\",'cbsWarehouseController.do?cbsWarehouse');",1000);
                                        setTimeout("closetab('添加')",1000);
                                    }else{
                                        // alert("你点击的是false");
                                    }
                                });
                            }
                        })
					}else{
					    tip("物流仓库名称已存在,请重新输入");
					    return false;
				  }
              }
		  })

      }
      function callBackValue() {
	    alert(123);
          var iframe = this.iframe.contentWindow;
      }
	function choose() {
	    var cityId = $("#SL1").text();
	    $.session.set("ids",cityId);
        $.dialog({
            content: "url:cbsWarehouseController.do?goChooseCity",
            zIndex: 2100,
            title: '选择城市',
            lock: true,
            width: '800px',
            height: '500px',
            left: '85%',
            top: '65%',
            opacity: 0.4,
            init: function () {
                top.myWindow = window;
            },

            button: [{
                name: '确认',
                callback: function () {
                    var iframe = this.iframe.contentWindow;
                    var cid =  iframe.$("#oneValue").val();
                    var cname =  iframe.$("#oneText").val();
                    var ckName = $.session.get("name");
                    if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                        var SL2=  $("#t2").text();
                        var SL3=  $("#t3").text();
                        var SL4=  $("#t4").text();

                        var   b = arrRepeat(cname,SL2,SL4,SL3);
                        if (b){
                            alert("一个目的地对应一个物流,请您重新选择城市");
							return false;
						}else {
                            $("#SL1").html("<span id='t1'>"+cname+"</span>");
                            $("#cityId").val(cid);
						}
                    }else {
                        $("#SL1").html("<span id='t1'></span>");
                        $("#cityId").val("");
					}
                    $.session.clear();
                },

                focus: true
            },
				{
                name: '返回'
            }]

        });
    }
      function choose2() {
          var cityId = $("#SL2").text();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity2",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#twoValue").val();
                      var cname =  iframe.$("#twoText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL1=  $("#t1").text();
                          var SL3=  $("#t3").text();
                          var SL4=  $("#t4").text();

                           var   b = arrRepeat(cname,SL1,SL4,SL3);

							if(b){
							    alert("一个目的地对应一个物流,请重新选择目的地城市");
                                return false;
							}else {
                                $("#SL2").html("<span id='t2'>"+cname+"</span>");
                                $("#cityId2").val(cid);
							}

                      }else {
                          $("#SL2").html("<span id='t2'></span>");
                          $("#cityId2").val("");
                      }
                      $.session.clear();
                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function arrRepeat(cname,s,t,t2) {
          var citys="";
          citys = citys.concat(cname,s,t,t2);
          var ary = citys.split(" ");
          var nary = ary.sort();

          var hash = {};
          for(var i in nary) {
              if(hash[nary[i]])
                  return true;
              hash[nary[i]] = true;
          }
          return false;
      }
      function choose4() {
          var cityId = $("#SL4").text();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity4",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#fourValue").val();
                      var cname =  iframe.$("#fourText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL2=  $("#t2").text();
                          var SL3=  $("#t3").text();
                          var SL1=  $("#t1").text();

                          var   b = arrRepeat(cname,SL2,SL1,SL3);
                          if(b){
                              alert("一个目的地对应一个物流,请重新选择城市");
                              return false;
						  }else{
                              $("#SL4").html("<span id='t4'>"+cname+"</span>");
                              $("#cityId4").val(cid);
						  }
                      }else{
                          $("#SL4").html("<span id='t4'></span>");
                          $("#cityId4").val("");
                      }
                      $.session.remove('city_id');
                      $.session.remove('city_name');
                      $.session.clear();
                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function choose3() {
          var cityId = $("#SL3").text();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity3",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#threeValue").val();
                      var cname =  iframe.$("#threeText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL2=  $("#t2").text();
                          var SL4=  $("#t4").text();
                          var SL1=  $("#t1").text();

                          var   b = arrRepeat(cname,SL2,SL1,SL4);
                          if(b){
                              alert("一个目的地对应一个物流,请重新选择城市");
                              return false;
						  }else {
                              $("#SL3").html("<span id='t3'>"+cname+"</span>");
                              $("#cityId3").val(cid);
						  }
                      }
                      $.session.remove('city_id');
                      $.session.remove('city_name');
                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function changeName() {
		  var name = $("#name").val();
		  $.session.set("name",name);
      }
      function wlName() {
          var wlName = $("#logistics").val();
          $.session.set("wlName",wlName);
      }
  </script>
 </head>
 <body>
  <%--<t:formvalid formid="formobj" dialog="false" layout="table">--%>
					<input id="id" name="id" type="hidden" value="${cbsWarehousePage.id }">
					<input id="createName" name="createName" type="hidden" value="${cbsWarehousePage.createName }">
					<input id="createBy" name="createBy" type="hidden" value="${cbsWarehousePage.createBy }">
					<input id="createDate" name="createDate" type="hidden" value="${cbsWarehousePage.createDate }">
					<input id="updateName" name="updateName" type="hidden" value="${cbsWarehousePage.updateName }">
					<input id="updateBy" name="updateBy" type="hidden" value="${cbsWarehousePage.updateBy }">
					<input id="updateDate" name="updateDate" type="hidden" value="${cbsWarehousePage.updateDate }">
  <div style="margin-bottom:10px;">
	  <img style="margin-bottom:-7px" src="../plug-in/login/images/dispatch bill.png">
	  <div style="position: absolute; text-align: center; width: 100%; margin-top:-20px;">
		  <a href="#" id="btn" class="easyui-linkbutton l-btn" onclick="addWare()">提交</a>
	  </div>
  </div>

  <div class="subtitle">
	  <p>基本信息</p>
	  <table class="nobordertable noborder">
		  <tbody>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>仓库名称:</label>
			  </td>
			  <td width="30%">
				  <input id="name" onchange="changeName()" onblur="ifNameIsNull()"/>
				  <span id="isName" hidden="hidden" style="color: red">仓库名称不能为空</span>
			  </td>
			  <td class="al_r" width="20%">
				  <label>物流:</label>
			  </td>
			  <td width="30%">
				  <select id="logistics" onchange="wlName()">
					  <c:forEach items="${tsDeparts}" var="depart">
						  <option value="${depart.departname}">${depart.departname}</option>
					  </c:forEach>
			  </td>
		  </tr>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>仓库代码:</label>
			  </td>
			  <td width="30%">
				  <input id="code" onblur="ifCodeIsNull()"/>
				  <span id="isCode" hidden="hidden" style="color: red">仓库代码不能为空</span>
			  </td>
			  <td class="al_r" width="20%">
				  <label>仓库所在地:</label>
			  </td>
			  <td width="30%">
				  <select style="width: auto;" id="sheng" onchange="getCity()">
					  <%--<option>北京</option>--%>
				  </select>
				  <select style="width: auto;" id="city">
					  <option value="0">--请选择--</option>
				  </select>
				  <%--<span id="isCity" hidden="hidden" style="color: red">收货地址不能为空</span>--%>
			  </td>
		  </tr>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>联系人姓名:</label>

			  </td>
			  <td width="30%">
				  <input id="userName" onblur="isNameIfNull()"/><span id="isUserName" hidden="hidden" style="color: red">姓名不能为空</span>
			  </td>
			  <td class="al_r" width="20%"><label>详细地址:</label></td>
			  <td width="30%"><input style="width:80%" id="address" name="address" onblur="isAddressIfNull()">
			  <span hidden="hidden" id="isAddress" style="color: red">请填写详细地址</span>
			  </td>

		  </tr>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>联系人邮箱:</label>
			  </td>
			  <td width="30%">
				  <input id="email" onblur="isEmailIfNull()"/>
				  <span id="isEmail" hidden="hidden" style="color: red">邮箱不能为空</span>
				  <span id="ifEmail" hidden="hidden" style="color: red">请检查邮箱格式是否正确</span>
			  </td>
			  <td class="al_r" width="20%">
				  <label>联系人电话:</label>
			  </td>
			  <td width="30%">
				  <input id="phone" onblur="isPhoneIfNull()"/>
				  <span id="isPhoe" hidden="hidden" style="color: red">手机不能为空</span>
				  <span id="ifPhoe" hidden="hidden" style="color: red">请检查手机号格式是否正确</span>
			  </td>
		  </tr>
		  </tbody>
	  </table>
	  <div style="margin-top:10px;">
		  SL1目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose()">选择</a>
		  <div class="l-div" id="SL1" style="height: 20px">

		  </div>
		  <input type="hidden" id="cityId">
	  </div>
	  <div style="margin-top:10px;">
		  SL2目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose2()">选择</a>
		  <div class="l-div" id="SL2" style="height: 20px" >
		  </div>
		  <input type="hidden" id="cityId2">
	  </div>
	  <div style="margin-top:10px;">
		  SL3目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose3()">选择</a>
		  <div class="l-div" id="SL3" style="height: 20px">

		  </div>
		  <input type="hidden" id="cityId3">
	  </div>
	  <div style="margin-top:10px;">
		  SL4目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose4()">选择</a>
		  <div class="l-div" id="SL4" style="height: 20px">

		  </div>
		  <input type="hidden" id="cityId4">
	  </div>
  </div>
  <div id="dialog-modal"></div>
  <%--</t:formvalid>--%>
 </body>
  <script src = "webpage/com/zybk/cbswarehouse/cbsWarehouse.js"></script>